<?php

require_once dirname(__FILE__).'/src/Tb.php';
require_once dirname(__FILE__).'/src/TbParser.php';

$conf = [
    'template_root_dir' => dirname(__FILE__).'/template/',
    'cache_root_dir'    => dirname(__FILE__).'/runtime/view/parse',
];
$t = new Town\View\Tb($conf, true);
$parameters = [
    'name'  => '张三',
    'email' => 'nice2u@qq.com',
    'age'   => 25,
];
$text = $t->fetch('dir.child', $parameters);
var_dump($text);
exit();



/**
 * 测试include
 */
require_once dirname(__FILE__).'/src/Tb.php';
require_once dirname(__FILE__).'/src/TbParser.php';

$conf = [
    'template_root_dir' => dirname(__FILE__).'/template/',
    'template_name'     => 'include',
    'template_ext'      => 'html',
    'cache_root_dir'    => dirname(__FILE__).'/runtime/view/parse',
];
$t = new Town\View\Tb($conf, true);
$t->setParameter('name', '张三');
$t->setParameter('email', 'nice2u@mailto.com');
$t->setParameter('age', 23);
$text = $t->render();
var_dump($text);
exit();


/**
 * 测试条件判断
 */
require_once dirname(__FILE__).'/src/Tb.php';
require_once dirname(__FILE__).'/src/TbParser.php';

$conf = [
    'template_root_dir' => dirname(__FILE__).'/template/',
    'template_name'  => 'for',
    'template_ext'   => 'html',
    'cache_root_dir' => dirname(__FILE__).'/runtime/view/parse',
];
$t = new Town\View\Tb($conf, true);
$t->setParameter('list', [
    [
        'name'  => '张三1',
        'age'   => '31',
        'salary'=> '23333333',
        'sex'   => 'male',
    ],
    [
        'name'  => '张三2',
        'age'   => '32',
        'salary'=> '23333333',
        'sex'   => 'male',
    ],
    [
        'name'  => '张三3',
        'age'   => '33',
        'salary'=> '23333333',
        'sex'   => 'male',
    ],
]);
$text = $t->render();
var_dump($text);
exit();


/**
 * 测试条件判断
 */
require_once dirname(__FILE__).'/src/Tb.php';
require_once dirname(__FILE__).'/src/TbParser.php';

$conf = [
    'template_root_dir' => dirname(__FILE__).'/template/',
    'template_name'  => 'child2',
    'template_ext'   => 'html',
    'cache_root_dir' => dirname(__FILE__).'/runtime/view/parse',
];
$t = new Town\View\Tb($conf, true);
$t->setParameter('name', 'lisi');
$text = $t->render();
var_dump($text);
exit();


/**
 * 测试参数
 */
require_once dirname(__FILE__).'/src/Tb.php';
require_once dirname(__FILE__).'/src/TbParser.php';

$conf = [
    'template_root_dir' => dirname(__FILE__).'/template/',
    'template_name'  => 'args',
    'template_ext'   => 'html',
    'cache_root_dir' => dirname(__FILE__).'/runtime/view/parse',
];
$t = new Town\View\Tb($conf, true);
$t->setParameter('name', '张三');
$t->setParameter('email', 'nice2u@mailto.com');
$text = $t->render();
var_dump($text);

exit();



/**
 * 测试循环,嵌套
 */
require_once dirname(__FILE__).'/src/Tb.php';
require_once dirname(__FILE__).'/src/TbParser.php';

$conf = [
    'template_root_dir' => dirname(__FILE__).'/template/',
    'template_name'  => 'child1',
    'template_ext'   => 'html',
    'cache_root_dir' => dirname(__FILE__).'/runtime/view/parse',
];
$t = new Town\View\Tb($conf, true);
$t->setParameter('name', '张三');
$t->setParameter('list', [
    [
        'name'  => '张三1',
        'age'   => '31',
        'salary'=> '23333333',
        'sex'   => 'male',
    ],
    [
        'name'  => '张三2',
        'age'   => '32',
        'salary'=> '23333333',
        'sex'   => 'male',
    ],
    [
        'name'  => '张三3',
        'age'   => '33',
        'salary'=> '23333333',
        'sex'   => 'male',
    ],
]);
$base = new stdClass();
$base->name = 'lisi';
$t->setParameter('base', $base);
$text = $t->render();
var_dump($text);

exit();